package com.opo5.logisticsmanagement.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.opo5.logisticsmanagement.common.R;
import com.opo5.logisticsmanagement.domain.New;
import com.opo5.logisticsmanagement.service.NewService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("newplan")
public class NewController {
    @Autowired(required = false)
    private NewService newService;

    /**
     *
     * @param n
     * @return
     */
    @PostMapping
    public R save(@RequestBody New n){
        newService.save(n);
        return R.success("添加成功");
    }

    /**
     *
     * @param currentPage
     * @param pageSize
     * @param n
     * @return
     */
    @GetMapping("/{currentPage}/{pageSize}")
    public R getAll(@PathVariable int currentPage,@PathVariable int pageSize,New n) {
        IPage<New> page = newService.selectPage(currentPage, pageSize, n);
        return R.success(page);
    }

    /**
     *
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    public R delList(@PathVariable int id){
        newService.removeById(id);
        return R.success("删除成功");
    }

    /**
     *
     * @param n
     * @return
     */
    @PutMapping
    public R putList(@RequestBody New n){
        newService.updateById(n);
        return R.success("修改成功");
    }
}
